#include "hx711.h"
#include "delay.h"
//****************************************************
//??
//****************************************************
sbit HX711_DOUT=P2^1; 
sbit HX711_SCK=P2^2;

unsigned long Weight_Maopi;
unsigned int GapValue = 500;
unsigned int qupi = 0;
unsigned int maopi = 0;
unsigned int maopi1 = 0;

void Delay__hx711_us(void)
{
	_nop_();
	_nop_();
}
//****************************************************
//??HX711
//****************************************************
unsigned long HX711_Read(void)	//??128
{
	unsigned long count; 
	unsigned char i; 
  	HX711_DOUT=1; 
	Delay__hx711_us();
  	HX711_SCK=0; 
  	count=0; 
  	while(HX711_DOUT); 
  	for(i=0;i<24;i++)				
	{ 
	  	HX711_SCK=1; 
	  	count=count<<1; 
		HX711_SCK=0; 
	  	if(HX711_DOUT)
			count++; 
	} 
 	HX711_SCK=1; 
    count=count^0x800000;//?25???????,????
	Delay__hx711_us();
	HX711_SCK=0;  
	return(count);
}

float m__1=3.40;

unsigned int Get_Weight_maopi()
{
	unsigned long HX711_Buffer = 0;
	unsigned int Weight_Shiwu = 0;
	unsigned long Weight_Maopi = 0;
	HX711_Buffer = HX711_Read();
	HX711_Buffer = HX711_Buffer/100;
	Weight_Shiwu = HX711_Buffer;
	Weight_Shiwu = Weight_Shiwu - 15500 ;//- maopi;				

	Weight_Shiwu = ((unsigned int)((float)Weight_Shiwu/m__1+0.05)); 



	if(Weight_Shiwu > 5000 )
	{
		Weight_Shiwu = 4998;	
	}
	else if(Weight_Shiwu < 0)
	{
		Weight_Shiwu = 0;
	}
	
	if(Weight_Shiwu < 5)Weight_Shiwu=0;
	
	return Weight_Shiwu;
}







unsigned int Get_Weight()
{
	unsigned long HX711_Buffer = 0;
	unsigned int Weight_Shiwu = 0;
	unsigned long Weight_Maopi = 0;
	HX711_Buffer = HX711_Read();
	HX711_Buffer = HX711_Buffer/100;
	Weight_Shiwu = HX711_Buffer;
	Weight_Shiwu = Weight_Shiwu - 15500 ;//- maopi;				

	Weight_Shiwu = ((unsigned int)((float)Weight_Shiwu/m__1+0.05)) - maopi; 



	if(Weight_Shiwu > 5000 )
	{
		Weight_Shiwu = 4998;	
	}
	else if(Weight_Shiwu < 0)
	{
		Weight_Shiwu = 0;
	}
	
	if(Weight_Shiwu < 5)Weight_Shiwu=0;
	
	return Weight_Shiwu;
	
}

